<template>
  <view class="content">
    <image src="/static/group_activity_banner.png" class="banner-image"></image>
    <view class="section-tit">相关商品</view>
    <view class="goods-list">
      <view v-for="(item, index) in productList" :key="index" class="goods-item" @click="navToDetailPage(item)">
        <view class="image-wrapper">
          <image :src="item.pic" mode="aspectFit"></image>
        </view>
        <text class="title clamp">{{item.name}}</text>
        <text class="title2">{{item.subTitle}}</text>
        <view class="price-box">
          <text class="price">{{item.price}}</text>
          <text>已售 {{item.sale}}</text>
        </view>
      </view>
    </view>
    <uni-load-more :status="loadingType"></uni-load-more>

  </view>
</template>

<script>
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import {fetchActivityGoodsList} from "@/api/activity";
export default {
  components: {
    uniLoadMore
  },
  data() {
    return {
      loadingType: 'more', //加载更多状态
      productList: [],
      searchParam: {
        pageNum: 1,
        pageSize: 6
      },
      activityId: null
    };
  },

  onLoad(options) {
    let id = options.activityId
    this.activityId = id
    this.loadData(id);
  },
  //下拉刷新
  onPullDownRefresh() {
    this.loadData('refresh');
  },
  //加载更多
  onReachBottom() {
    this.searchParam.pageNum++;
    this.loadData();
  },
  methods: {
    async loadData(id) {
      fetchActivityGoodsList(id).then(response=> {
        this.productList = response.data
      })
    },

    //详情
    navToDetailPage(item) {
      let id = item.skuId;
      uni.navigateTo({
        url: `/pages/activity/goods?skuId=${id}&activityId=`+this.activityId
      })
    },
    stopPrevent() {}
  },
}
</script>

<style lang="scss">
page,
.content {
  background: $page-color-base;
}
.banner-image{
  width: 100%;
}
.section-tit {
  font-size: $font-base+2upx;
  color: $font-color-dark;
  background: #fff;
  margin-top: 16upx;
  text-align: center;
  padding-top: 20upx;
  padding-bottom: 20upx;
}
/* 商品列表 */
.goods-list {
  display: flex;
  flex-wrap: wrap;
  padding: 0 30upx;
  background: #fff;

  .goods-item {
    display: flex;
    flex-direction: column;
    width: 48%;
    padding-bottom: 40upx;

    &:nth-child(2n+1) {
      margin-right: 4%;
    }
  }

  .image-wrapper {
    width: 100%;
    height: 330upx;
    border-radius: 3px;
    overflow: hidden;
    background-color: #fff;

    image {
      width: 100%;
      height: 100%;
      opacity: 1;
    }
  }

  .title {
    font-size: $font-lg;
    color: $font-color-dark;
    line-height: 80upx;
  }

  .title2 {
    font-size: $font-sm;
    color: $font-color-light;
    line-height: 40upx;
    height: 80upx;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
  }

  .price-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 10upx;
    font-size: 24upx;
    color: $font-color-light;
  }

  .price {
    font-size: $font-lg;
    color: $uni-color-primary;
    line-height: 1;

    &:before {
      content: '￥';
      font-size: 26upx;
    }
  }
}
</style>
